import { _decorator, Component, Node, Input, input, Graphics, director, view, EventMouse } from 'cc';
const { ccclass, property, } = _decorator;

@ccclass('Player')
export class Player extends Component {
    
    start() {
        // cc.systemEvent.on(cc.SystemEvent.EventType.MOUSE_DOWN, this.onMouseDown, this);
        // Input.on(Node.EventType.MOUSE_DOWN, this.onMouseDown, this, true);
        input.on(Input.EventType.MOUSE_DOWN, this.onMouseDown, this);
        // this.node.addComponent(Graphics);

        
        console.log(view.getVisibleSize(), 'getVisibleSize')
        console.log(view.getViewportRect(), 'getViewportRect')
        console.log(view.getVisibleSizeInPixel(), 'getVisibleSizeInPixel')
    }

    update(deltaTime: number) {
        
    }

    onMouseDown (event:EventMouse) {
        // let pos = event.getLocation();
        let p = event.getLocation();
        console.log(event);
        let g = this.node.getComponent(Graphics);
        // g.moveTo(event._x, event._y);
        g.clear()
        g.fillColor.fromHEX('#ffff00');
        // g.rect(event._x, event._y, 10, 10);
        g.rect(p.x, p.y, 10, 10)
        g.fill();

        // console.log(event._x, event._y)
        console.log(p)
        
        // let rectNode = cc.instantiate(this.rectPrefab);
        // rectNode.position = pos;
        // rectNode.width = 10;
        // rectNode.height = 10;
        // rectNode.color = cc.Color.RED;
        // this.node.addChild(rectNode);
    }

    break(){
        director.loadScene('index');
    }
}


